# FileSystemManager.appendFileSync(string filePath, string|ArrayBuffer data, string encoding)

以 Promise 风格调用:不支持

# 功能描述

FileSystemManager.appendFile 的同步版本

# 参数

# string filePath

要追加内容的文件路径 (本地路径)

# string|ArrayBuffer data

要追加的文本或二进制数据

# string encoding

指定写入文件的字符编码

encoding 的合法值

说明
ascii
base64
binary
hex
ucs2以小端序读取
ucs-2以小端序读取
utf16le以小端序读取
utf-16le以小端序读取
utf-8
utf8
latin1

# 错误

错误码错误信息说明
1300001operation not permitted操作不被允许(例如,filePath 预期传入一个文件而实际传入一个目录)
1300002no such file or directory ${path}文件/目录不存在,或者目标文件路径的上层目录不存在
1300005Input/output error输入输出流不可用
1300009bad file descriptor无效的文件描述符
1300013permission denied权限错误,文件是只读或只写
1300014Path permission denied传入的路径没有权限
1300020not a directorydirPath 指定路径不是目录,常见于指定的写入路径的上级路径为一个文件的情况
1300021Is a directory指定路径是一个目录
1300022Invalid argument无效参数,可以检查length或offset是否越界
1300036File name too long文件名过长
1300066directory not empty目录不为空
1300201system error系统接口调用失败
1300202the maximum size of the file storage limit is exceeded存储空间不足,或文件大小超出上限(上限100M)
1300203base64 encode error字符编码转换失败(例如 base64 格式错误)
1300300sdcard not mountedandroid sdcard 挂载失败
1300301unable to open as fileType无法以fileType打开文件
1301000permission denied, cannot access file path目标路径无访问权限(usr目录)
1301002data to write is empty写入数据为空
1301003illegal operation on a directory不可对目录进行此操作(例如,指定的 filePath 是一个已经存在的目录)
1301004illegal operation on a package directory不可对代码包目录进行此操作
1301005file already exists ${dirPath}已有同名文件或目录
1301006value of length is out of range传入的 length 不合法
1301007value of offset is out of range传入的 offset 不合法
1301009value of position is out of rangeposition值越界
1301100store directory is emptystore目录为空
1301102unzip open file fail压缩文件打开失败
1301103unzip entry fail解压单个文件失败
1301104unzip fail解压失败
1301111brotli decompress failbrotli解压失败(例如,指定的 compressionAlgorithm 与文件实际压缩格式不符)
1301112tempFilePath file not exist指定的 tempFilePath 找不到文件
1302001fail permission denied指定的 fd 路径没有读权限/没有写权限
1302002excced max concurrent fd limitfd数量已达上限
1302003invalid flag无效的flag
1302004permission denied when open using flag无法使用flag标志打开文件
1302005array buffer does not exist未传入arrayBuffer
1302100array buffer is readonlyarrayBuffer只读

# 示例代码

const fs = tap.getFileSystemManager()

fs.appendFile({
  filePath: `${tap.env.USER_DATA_PATH}/hello.txt`,
  data: 'some text',
  encoding: 'utf8',
  success(res) {
    console.log(res)
  },
  fail(res) {
    console.error(res)
  }
})

// 同步接口
try {
  fs.appendFileSync(`${tap.env.USER_DATA_PATH}/hello.txt`, 'some text', 'utf8')
} catch(e) {
  console.error(e)
}